﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PropertyManagement.Core.Model;
using System.Data;
using System.Data.SqlClient;
namespace PropertyManagement.Core.DataAccess {
    public static partial  class HouseOwnerDataAccess {
       public static IEnumerable<HouseOwner> SearchByHouseCode(string houseCode) {
           var sql = "select * from dbo.HouseOwner where HouseCode like '%" + houseCode + "%'";
           var list = new List<HouseOwner>( );
           using (var iReader = SqlServerHelper.ExecuteReader(SqlServerHelper.ConnectionString, CommandType.Text, sql)) {
               while (iReader.Read( )) {
                   list.Add(CreationHouseOwnerByIReader(iReader));
               };
           }
           return list;
       } 

        public static IEnumerable<HouseOwner> SearchByHouseCodeAndName(string houseCode, string ownerName) {
            var sql = "select * from dbo.HouseOwner where 1=1";
            if (!string.IsNullOrEmpty(houseCode)) {
                sql += " and  HouseCode like '%" + houseCode + "%'";
            }
            if (!string.IsNullOrEmpty(ownerName)) {
                sql += " and OwnerName like '%" + ownerName + "%'";
            }
            var list = new List<HouseOwner>( );
            using (var iReader = SqlServerHelper.ExecuteReader(SqlServerHelper.ConnectionString, CommandType.Text, sql)) {
                while (iReader.Read( )) {
                    list.Add(CreationHouseOwnerByIReader(iReader));
                };
            }
            return list;
        } 
    }
}
